package models

import (
	"fmt";
	"bufio";
	"os";
)

type Player struct {
	name		string;
	num_moves	int;
	position	Point;
}

func NewPlayer() (player *Player) {
	player = new(Player);
	player.name = "Unnamed";
	player.num_moves = 0;
	player.position = Point{0, 0};
	return;
}

func (this *Player) GetName() string	{ return this.name }

func (this *Player) SetName(name string)	{ this.name = name }

func (this *Player) GetPosition() Point	{ return this.position }

func (this *Player) PromptName() {
	fmt.Printf("Type in your name: ");
	line, _ := bufio.NewReader(os.Stdin).ReadString('\n');
	this.SetName(line[0 : len(line)-1]);
}

func (this *Player) MovePlayer(how_many int) {
	if how_many == -1 {
		how_many = RollDie()
	}

	this.num_moves++;

	this.position.X += how_many;

	// if displacement causes player to clash with x boundary
	if this.position.X >= MAX_WIDTH {
		this.position.X = this.position.X % MAX_WIDTH;
		this.position.Y++;
	}
}
